import Vue from "vue";
import VueRouter from "vue-router";
import routes from "./routes"
import NProgress from "nprogress"
import "nprogress/nprogress.css"

Vue.use(VueRouter);
//重写push和replace 
const oldPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (
    loaction, 
    onComplate = () => { }, 
    onAbort = () => { }) {
        oldPush.call(this,loaction, onComplate, onAbort)
}
const oldReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function (
    loaction, 
    onComplate = () => { }, 
    onAbort = () => { }) {
        oldReplace.call(this,loaction, onComplate, onAbort)
}

const router = new VueRouter({
    mode: "history",
    routes,
})

//全局前置守卫
router.beforeEach((to,from,next)=>{
    NProgress.start();
    next();
})
//全局后置钩子
router.afterEach(()=>{
    NProgress.done();
})

export default router;